package de.szut.bomberman.game.logic;


import java.util.ArrayList;

import javax.swing.JLabel;

public class CollisionControl {

	private ArrayList<JLabel> stones;
	private JLabel labelToMove;

	public CollisionControl(ArrayList<JLabel> stones, JLabel movingLabel) {
		this.stones = stones;
		labelToMove = movingLabel;
	}

	public boolean noCollision(Direction direction) {

		switch (direction) {

		case RIGHT:
			for (JLabel p : stones) {
				if (p.getY() - 40 < labelToMove.getLocation().getY()
						&& p.getY() + 40 > labelToMove.getLocation().getY()
						&& p.getX() - 50 == labelToMove.getLocation().getX()) {
					return false;
				}
			}
			return true;

		case LEFT:
			for (JLabel p : stones) {
				if (p.getY() - 40 < labelToMove.getLocation().getY()
						&& p.getY() + 40 > labelToMove.getLocation().getY()
						&& p.getX() + 50 == labelToMove.getLocation().getX()) {
					return false;
				}
			}
			return true;

		case UP:
			for (JLabel p : stones) {
				if (p.getX() - 40 < labelToMove.getLocation().getX()
						&& p.getX() + 40 > labelToMove.getLocation().getX()
						&& p.getY() + 50 == labelToMove.getLocation().getY()) {
					return false;
				}
			}
			return true;

		case DOWN:
			for (JLabel p : stones) {
				if (p.getX() + 40 > labelToMove.getLocation().getX()
						&& p.getX() - 40 < labelToMove.getLocation().getX()
						&& p.getY() - 50 == labelToMove.getLocation().getY()) {
					return false;
				}
			}
			return true;
		case DEFAULT:
			break;

		}

		return false;
	}
}
